import api from '@/api'
import tool from '@/utils/tool'

export default {
	state: {
		name: '',
		logo: '',
		title: '',
		desc: '',
		version: '',
		copyright: '',
	},
	mutations: {
		admininfo(state, info) {
			state.name = info.admin_name;
			state.logo = info.admin_logo
			state.title = info.admin_title
			state.desc = info.admin_desc
			state.version = info.admin_version
			state.copyright = info.admin_copyright
		},
	},
	actions: {
		getinfo({commit}) {
			return new Promise((resolve, reject) => {
				let data = tool.data.get("admin");
				if (data) {
					commit('admininfo', data);
					resolve(data)
				} else {
					api.system.info.get().then((res) => {
						commit('admininfo', res.data);
						tool.data.set("admin", res.data)
						resolve(res)
					}).catch(e => {
						reject(e)
					})
				}

			})
		}
	}
}
